package setting;
import java.util.Hashtable;
import java.util.regex.Pattern;

import util.io.FileUtil;



public class BioNLPSettings {
	// make it read a config file
	public static void init(String filename){
		setDefault();
		String[] lines = FileUtil.getTextFromFile(filename).split("\n");
		for (String line: lines){
			if (line.startsWith("\\")){
				System.err.println("[BIONLPSETTINGS_INIT]skipping : "+line);
				continue;
			}
			String[] pair = line.split("\\s*=\\s*");
			if (pair.length!=2){
				System.err.println("[BIONLPSETTINGS_INIT]can't recognize : "+line);
				continue;
			}
			values.put(pair[0], pair[1]);
		}
	}

	public static void print(){
		for (String key: values.keySet()){
			System.err.println("[SETTINGS]"+key+"="+values.get(key)+";");
		}
	}
	
	public static void setDefault(){
		// eval
		values.put("evalMethod", EVAL_APPROX);
		// trigger
		values.put(	 "TRIGGER_DETECTOR", "TRIGGER_DICT");
		values.put("triggerFrequency", "0");
		values.put("triggerLength","2");
		values.put("patternFreq","0");
		values.put("TRIGGER_DICT", "trigger.dict.refined");
		values.put("REG_TRIGGER_DICT", "parentTrigger.dict");
		// trigger svm model
		values.put("BIND_TRIGGER_DICT", "bindingTrigger.dict");
		values.put("TRIGGER_MODEL", "svm_trigger_model");
		values.put("triggerFeatureMap", "triggerFeatureMap");
		values.put(	"SVM_TRIGGER_THRESHOLD", "-0.6");
		// edge
		values.put("USE_DEP_SIGN", "false");
		values.put("EDGE_DETECTOR", BioNLPSettings.EDGE_DICT_DETECTOR);
		values.put("LINK_THRESHOLD", "-0.1");
		values.put("ROLE_THRESHOLD", "0.0");
		// data
		values.put("EventAnnotationSuffix", ".a2");
		values.put("parsePath", "");
		values.put(	"PRED_DIR", "predictions/");

		// search related
		values.put("BP","2");
		values.put("BE","2");
		values.put("DP","1");
		values.put("DE","1");
		values.put( "MAX_LEVEL", "4");
		values.put("MAX_CHOOSE", "2");
		values.put(	"maxPerc", "0.35");

		// mode
		values.put("mode", "NONE");
	}

	public static Hashtable<String, String> values = new Hashtable<String, String>();

	public static String getValue(String key){
		return values.get(key);
	}

	public static int getIntValue(String key){
		if (values.containsKey(key))
			return Integer.parseInt(values.get(key));
		else
			return -1;
	}

	public static boolean getBooleanValue(String key){
		if (values.containsKey(key)){
			return Boolean.parseBoolean(values.get(key));
		}
		else{
			return false;
		}
	}
	
	public static float getFloatValue(String key){
		if (values.containsKey(key)){
			return Float.parseFloat(values.get(key));
		}
		else{
			return 0.0f;
		}
	}
	
	public static void setValue(String key, String value){
		values.put(key, value);
	}

	// should work in this domain
	
	public static final Pattern sentSplitter = Pattern.compile("(\\.\\s+|\\?\\s+)([A-Z0-9\\(\"]|[a-z]\\w*\\-|[a-z]\\w*\\d+\\w*|[a-z][A-Z]+|alpha|beta|gamma)");//|\n
	// FIXME: should be "(;\\s+)(and)?\\s*\\((i|v)+\\)\\s+"
	public static final Pattern clauseSplitter = Pattern.compile("(;\\s+)\\((i|v)+\\)\\s+");
	
	/*public static SentenceDetectorME sentenceDetector = null;
	static{
		try {
			SentenceModel sentModel = null;
			InputStream modelIn = new FileInputStream("en-sent.bin");
			sentModel= new SentenceModel(modelIn);
			modelIn.close();
			sentenceDetector = new SentenceDetectorME(sentModel);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
	}*/

	
	// evaluation method
	public static final String EVAL_STRICT = "STRICT";
	// event trigger span could be within the gold span extended to the left one and right one word as well
	public static final String EVAL_APPROX = "APPROX";
	// events considered as matching even if non-theme arguments are incorrect
	public static final String EVAL_APPROX_RECURSIVE = "APP_REC";
	//	public static String evalMethod = EVAL_APPROX;

	// for debug
	//	public static final int triggerFrequency = 0;
	//	public static final int triggerLength = 2;
	//	public static final int patternFreq = 0 ;

	//	public static final boolean USE_DEP_SIGN = false;

	public static final String TRIGGER_DICT = "trigger.dict.refined";
	public static final String REG_TRIGGER_DICT = "parentTrigger.dict";
	public static final String BIND_TRIGGER_DICT = "bindingTrigger.dict";

	// file suffixes
//	public static String EventAnnotationSuffix = ".a2";
	// parse path
//	public static String parsePath = "";

	// BP: upper bound of number of events only taking events for the same trigger
	// BE: ub of number of events not only taking events for the same trigger
	// DP: ub of number of triggers taking only proteins that have duplicates in one sentence
	//	DE: ub of number of triggers taking not only proteins that have duplicates in one sentence
	//	public static int BP = 7, BE = 8, DP = 3, DE = 3;
	//	public static int BP = 2, BE = 2, DP = 1, DE = 1;
	//	public static int MAX_LEVEL = 4;
	//	public static int MAX_CHOOSE = 2;
	//	public static double maxPerc = 0.35;
	//	public static final double SVM_TRIGGER_THRESHOLD = -0.6;

	// path
	public static final String trainParsePath = "bionlp09_shared_task_training_analyses_rev2/McClosky-Charniak";
	public static final String devParsePath = "bionlp09_shared_task_devel_analyses_rev2/McClosky-Charniak";
	public static final String testParsePath = "bionlp09_shared_task_test_analyses_rev2/McClosky-Charniak";
	//	public static final String PRED_DIR = "test_predictions/";
	//	public static final String PRED_DIR = "predictions/";

	public static final String TRIGGER_DICT_DETECTOR = "TRIGGER_DICT";
	public static final String TRIGGER_SVM_DETECTOR = "TRIGGER_SVM";
	public static final Object TRIGGER_ORACLE_DETECTOR = "TRIGGER_ORACLE";
	public static final Object TRIGGER_REFINER_DETECTOR = "TRIGGER_REFINER";
	
	//	public static String TRIGGER_DETECTOR = TRIGGER_DICT_DETECTOR;
	public static final String EDGE_DICT_DETECTOR = "EDGE_DICT";
	public static final String EDGE_SVM_DETECTOR = "EDGE_SVM";
	

}
